<template>
	<el-dialog :title="titleMap[mode]" v-model="visible" :width="400" destroy-on-close @closed="$emit('closed')">
		<el-form :model="form" :rules="rules" ref="dialogForm" label-width="100px" label-position="left">
			<el-form-item label="排序号" prop="sortNo">
				<el-input-number v-model="form.sortNo" controls-position="right" :min="1" style="width: 100%;"></el-input-number>
			</el-form-item>
			<el-form-item label="会议室名称" prop="name">
				<el-input v-model="form.name" placeholder="会议室名称" maxlength="48" clearable></el-input>
			</el-form-item>
			<el-form-item label="会议室位置" prop="address">
				<el-input v-model="form.address" placeholder="会议室位置" maxlength="48" clearable></el-input>
			</el-form-item>
			<el-form-item label="会议室规模" prop="userCount">
				<el-input-number v-model="form.userCount"  :min="1"></el-input-number>/人
			</el-form-item>
			<el-form-item label="管理员" prop="manager">
				<select-user-dialog v-model:accountId="form.manager" :mode="false"/>
			</el-form-item>
			<el-form-item label="开放范围" prop="deptRole">
				<select-dept-dialog v-model:deptId="form.deptRole" :mode="true"/>
			</el-form-item>
			<el-form-item label="是否启用" prop="status">
				<el-switch v-model="form.status" active-value="1" inactive-value="0"></el-switch>
			</el-form-item>
			<el-form-item label="备注">
				<el-input type="textarea" :rows="2" maxlength="280" placeholder="设备备注" v-model="form.remark"></el-input>
			</el-form-item>
		</el-form>
		<template #footer>
			<el-button @click="visible=false">取 消</el-button>
			<el-button type="primary" :loading="isSaveing" @click="submit()">保 存</el-button>
		</template>
	</el-dialog>
</template>

<script>
import selectUserDialog from "@/views/module/selectUserDialog";
import selectDeptDialog from "@/views/module/selectDeptDialog";
export default {
	components: {
		selectUserDialog,
		selectDeptDialog
	},
	emits: ['success', 'closed'],
	data() {
		return {
			mode: "add",
			titleMap: {
				add: '新增会议室',
				edit: '编辑会议室'
			},
			form: {
				roomId: "",
				name: "",
				sortNo:"",
				address: "",
				userCount:0,
				manager:'',
				deptRole:'',
				remark: "",
				status: "1"
			},
			rules: {
				name: [
					{required: true, message: '会议室名称不能为空'}
				],
				address: [
					{required: true, message: '会议室位置不能为空'}
				],
				userCount: [
					{required: true, message: '会议室规模不能为空'}
				],
				manager: [
					{required: true, message: '请指定会议室管理员'}
				],
				sortNo: [
					{required: true, message: '请输入排序', trigger: 'change'}
				],
			},
			visible: false,
			isSaveing: false,
		}
	},
	mounted() {

	},
	methods: {
		//显示
		open(mode = 'add') {
			this.mode = mode;
			this.visible = true;
			return this;
		},
		//表单提交方法
		submit() {
			this.$refs.dialogForm.validate(async (valid) => {
				if (valid) {
					var res;
					if(this.mode=="add")
					{
						this.isSaveing = true;
						res = await this.$API.office.meeting.insertMeetingRoom.post(this.form);
						this.isSaveing = false;
					}else if(this.mode=="edit")
					{
						this.isSaveing = true;
						res = await this.$API.office.meeting.updateMeetingRoom.post(this.form);
						this.isSaveing = false;
					}
					if (res.code == 200) {
						this.$emit('success', this.form, this.mode)
						this.visible = false;
						this.$message.success("操作成功")
					} else {
						this.$alert(res.message, "提示", {type: 'error'})
					}
				}
			})
		},
		setData(data) {
			this.form.roomId = data.roomId
			this.form.name = data.name
			this.form.sortNo = data.sortNo
			this.form.address = data.address
			this.form.deptRole = data.deptRole
			this.form.userCount = data.userCount
			this.form.manager = data.manager
			this.form.remark = data.remark
			this.form.status = data.status
		}
	}
}
</script>

<style>
</style>
